package cn.wzc.crystal.platform.query.impl;

import lombok.Getter;

@Getter
public class PrepareSqlParts {

	private final String part;
	private final String placeholder;
	private final boolean plan;
	private final boolean rightParent;

	public PrepareSqlParts(String part) {
		this.plan = !part.startsWith(":");

		if (this.isPlan()) {
			this.part = part;
			this.placeholder = null;
			this.rightParent = false;
			return;
		}

		this.part = null;
		if (part.endsWith(")")) {
			this.rightParent = true;
			this.placeholder = part.substring(1, part.length() - 1);
		} else {
			this.rightParent = false;
			this.placeholder = part.substring(1);
		}
	}

	/**
	 * 普通部分,直接输出
	 *
	 * @return true 表示是
	 */
	public boolean isPlan() {
		return plan;
	}

	/**
	 * 预编译站位块,进行编译后输出
	 *
	 * @return true 表示是
	 */
	public boolean isPlaceholder() {
		return !plan;
	}
}

